package java6681.string;

public class PasswordUnit6681 {

    public static void main(String[] args) {
        int testNum = 9;
        String[] arr = {"1234", "123456", "", "     ", "123a465s", "1245E2AS",
                "QWEASzxc", " 51sd sadAS  ", "123QWEzxc12"};

        String[] arr1 = {"false", "false", "false", "false", "false", "false",
                "false", "false", "true", "false"};

        for (int i = 0; i < testNum; i++) {
            boolean b = isSafe6681(arr[i]);
            System.out.println("测试用例编号：" + i);
            System.out.println("输入:" + arr[i]);
            System.out.print("预期结果:" + arr1[i]);
            System.out.println("实际运行结果:" + isSafe6681(arr[i]));
            if (b = false) {
                System.out.println("未通过测试");
            } else {
                System.out.println("通过测试");
            }

            System.out.println("");
        }

    }

    public static boolean isSafe6681(String s) {
        char ch;
        boolean upperLetter = false;
        boolean lowerLetter = false;
        boolean number = false;
//        长度小于6返回false
        if (s.length() < 6) {
            return false;
        }
//        包含空格返回返回false
        if (s.startsWith(" ") && s.endsWith(" ")) {
            return false;
        }
        if (s.trim().isEmpty()) {
            return false;
        }
//        判断是否包含大小写字母，数字
        for (int i = 0; i < s.length(); i++) {
            ch = s.charAt(i);
            if (Character.isDigit(ch)) {
                number = true;
            } else if (Character.isUpperCase(ch)) {
                upperLetter = true;
            } else if (Character.isLowerCase(ch)) {
                lowerLetter = true;
            }
            if (number && upperLetter && lowerLetter)
                return true;
        }
        return false;
    }

}
